//
//  DMSetController.m
//  DMGME
//
//  Created by ihope99 on 15/9/16.
//  Copyright (c) 2015年 GYP. All rights reserved.
//

#import "DMSetController.h"
#import "DMLogInController.h"
#import "WebViewController.h"
#import "AboutUsController.h"

@interface DMSetController ()<UITableViewDataSource,UITableViewDelegate>


@end

@implementation DMSetController
{
    NSArray *arrStr;
    NSArray *arrStrImage;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"设置";
    [self AddLeftImageBtn:[UIImage imageNamed:@"fanhui_03 2"]target:self action:@selector(GoBack)];
    
    UITableView *tableview = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    tableview.dataSource = self;
    tableview.delegate = self;
    tableview.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:tableview];
    arrStr = @[@"使用帮助",@"使用协议",@"关于动漫购"];
    arrStrImage = @[@"help",@"paper",@"about"];
    
    UIView *bactFootView = [[UIView alloc] init];
    bactFootView.frame = CGRectMake(0, 0, KWidth, 100);
    
    UIButton *quitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    quitBtn.frame = CGRectMake((KWidth - 250)/2 , 15, 250, 47);
    [quitBtn addTarget:self action:@selector(quitBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [quitBtn setImage:[UIImage imageNamed:@"Quit@2x"] forState:UIControlStateNormal];
    [bactFootView addSubview:quitBtn];
    
    [tableview setTableFooterView:bactFootView];
    
    // Do any additional setup after loading the view from its nib.
}

- (void)quitBtnClick{
    [self.view removeFromSuperview];
    
    DMLogInController *dmHomeVC = [[DMLogInController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:dmHomeVC];
      [self presentViewController:nav animated:YES completion:nil];
    self.view.window.rootViewController = nav;
    
    kkUserDict = nil;
    kkStatus = nil;
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"openid"];

//    NSLog(@"openid == %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"openid"]);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return arrStr.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *ID =@"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID ];
    if (cell==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    cell.textLabel.text = arrStr[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",arrStrImage[indexPath.row]]] ;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
    if (indexPath.row == 0) {
        WebViewController *web = [[WebViewController alloc] init];
        web.strType = @"0";
        [self.navigationController pushViewController:web animated:YES];
    }else if (indexPath.row == 1){
        WebViewController *web = [[WebViewController alloc] init];
        web.strType = @"1";
        [self.navigationController pushViewController:web animated:YES];
    }else{
        
        AboutUsController *about = [[AboutUsController alloc] initWithNibName:@"AboutUsController" bundle:nil];
        [self.navigationController pushViewController:about animated:YES];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
